package main

import (
	"fmt"
	"net/http"
	"time"
)

func hello(w http.ResponseWriter, req *http.Request) {
	for {
		select {
		case <-req.Context().Done():
			fmt.Println("request done")
			fmt.Fprintf(w, "request done")
			return
		default:
			fmt.Println("hello")
			time.Sleep(1 * time.Second)
		}
	}
}

func headers(w http.ResponseWriter, req *http.Request) {
	for name, headers := range req.Header {
		for _, h := range headers {
			fmt.Fprintf(w, "%v: %v\n", name, h)
		}
	}
}

func main() {

	http.HandleFunc("/hello", hello)
	http.HandleFunc("/headers", headers)

	http.ListenAndServe(":8080", nil)
}
